package com.cskaoyan.service.impl;

import com.cskaoyan.bean.FeedbackParameter;
import com.cskaoyan.bean.PageData;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import com.cskaoyan.model.MarketFeedback;
import com.cskaoyan.model.MarketFeedbackExample;
import com.cskaoyan.service.FeedbackService;
import com.cskaoyan.utils.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class FeedbackServiceImpl implements FeedbackService {
    @Override
    public PageData list(FeedbackParameter feedbackParameter) {
        SqlSession sqlsession = MyBatisUtil.getSqlSession();
        MarketFeedbackMapper mapper = sqlsession.getMapper(MarketFeedbackMapper.class);
        MarketFeedbackExample marketFeedbackExample = new MarketFeedbackExample();
        MarketFeedbackExample.Criteria criteria = marketFeedbackExample.createCriteria();

        criteria.andDeletedEqualTo(false);
        //分页
        Integer page = feedbackParameter.getPage();
        Integer limit = feedbackParameter.getLimit();
        PageHelper.startPage(page, limit);
        //排序
        String sort = feedbackParameter.getSort();
        String order = feedbackParameter.getOrder();
        marketFeedbackExample.setOrderByClause(sort + " " + order);
        //条件
        Integer id = feedbackParameter.getId();
        if (id != null && id != 0) {
            criteria.andIdEqualTo(id);
        }
        String username = feedbackParameter.getUsername();
        if (username != null & !"".equals(username)) {
            criteria.andUsernameLike("%" + username + "%");
        }
        List<MarketFeedback> marketFeedbackList = mapper.selectByExample(marketFeedbackExample);

        sqlsession.commit();
        sqlsession.close();
        return PageData.list(marketFeedbackList);
    }
}


